<template>
  <el-row class="login-box">
        <el-col :span="7" class="box">
            <h3>小U商城后台管理系统</h3>
            <el-form :model="loginform" ref="loginform" :rules="rules">
                <el-form-item prop="username">
                    <el-input placeholder="请输入账号" v-model="loginform.username">
                        <template slot="prepend"><i class="el-icon-user"></i></template>
                    </el-input>
                </el-form-item>
                <el-form-item  prop="password">
                    <el-input placeholder="请输入密码" v-model="loginform.password" show-password>
                        <template slot="prepend"><i class="el-icon-lock"></i></template>
                    </el-input>
                </el-form-item>
                <el-button type="primary" class="btn-login" @click="login" >立即登录</el-button>
            </el-form>
        </el-col>
  </el-row>
</template>

<script>
import { login } from "@/request/admin" 
import $axios from "@/common/http"
export default {
    data(){
        return{
            loginform:{
                username:"admin",
                password:"123"
            },
            rules:{
                username:[
                    {  required:true, message:"账号必须有！" }
                ],
                password:[
                    {  required:true, message:"密码必须有！" }
                ]
            }
        }
    },
    methods:{
        login(){
            this.$refs.loginform.validate(async isok=>{
                if(isok){
                    let userinfo = await login(this.loginform);
                    this.$store.commit('SETUSERINFO',userinfo);
                    this.$router.push("/home")  
                }
           })    
        }
    }
}

</script>
<style scoped>
.login-box{
    width: 100vw;
    height:100vh;
    background-image: url("../assets/img/loginbg.jpeg");
    background-position: center center;
    display: flex;
    justify-content: center;
    align-items: center;
}
.login-box .box{
    background-color: #fff;
    padding: 35px;
    border-radius: 5px;
    box-shadow: 0 0 10px 0 rgba(0, 0, 0, .6);
}
.login-box .box h3{
    text-align: center;
    line-height: 40px;
    font-size: 20px;
    color: #FB6D49;
    margin-bottom: 20px;
}
.btn-login{
    display: block;
    width: 100%;
    margin: 0 auto;
}
</style>